package androidx.transition;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import androidx.annotation.NonNull;
import java.util.Map;
import o.ng;
import o.nh;
import o.nu$b;
import o.nx;

public class ChangeImageTransform extends Transition {
    private static final Property<ImageView, Matrix> ʻ = new Property<ImageView, Matrix>(Matrix.class, "animatedTransform") {
        public /* synthetic */ Object get(Object obj) {
            return ˊ((ImageView) obj);
        }

        public /* synthetic */ void set(Object obj, Object obj2) {
            ॱ((ImageView) obj, (Matrix) obj2);
        }

        public void ॱ(ImageView imageView, Matrix matrix) {
            nh.ˊ(imageView, matrix);
        }

        public Matrix ˊ(ImageView imageView) {
            return null;
        }
    };
    private static final String[] ˋ = new String[]{"android:changeImageTransform:matrix", "android:changeImageTransform:bounds"};
    private static final TypeEvaluator<Matrix> ᐝ = new TypeEvaluator<Matrix>() {
        public /* synthetic */ Object evaluate(float f, Object obj, Object obj2) {
            return ॱ(f, (Matrix) obj, (Matrix) obj2);
        }

        public Matrix ॱ(float f, Matrix matrix, Matrix matrix2) {
            return null;
        }
    };

    static /* synthetic */ class AnonymousClass3 {
        static final /* synthetic */ int[] ˊ = new int[ScaleType.values().length];

        static {
            try {
                ˊ[ScaleType.FIT_XY.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                ˊ[ScaleType.CENTER_CROP.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
        }
    }

    public ChangeImageTransform(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    private void ˎ(nx nxVar) {
        View view = nxVar.ॱ;
        if ((view instanceof ImageView) && view.getVisibility() == 0) {
            ImageView imageView = (ImageView) view;
            if (imageView.getDrawable() != null) {
                Map map = nxVar.ˊ;
                map.put("android:changeImageTransform:bounds", new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()));
                map.put("android:changeImageTransform:matrix", ˏ(imageView));
            }
        }
    }

    public void ˋ(@NonNull nx nxVar) {
        ˎ(nxVar);
    }

    public void ॱ(@NonNull nx nxVar) {
        ˎ(nxVar);
    }

    public String[] ˋ() {
        return ˋ;
    }

    public Animator ˋ(@NonNull ViewGroup viewGroup, nx nxVar, nx nxVar2) {
        if (nxVar == null || nxVar2 == null) {
            return null;
        }
        Rect rect = (Rect) nxVar.ˊ.get("android:changeImageTransform:bounds");
        Rect rect2 = (Rect) nxVar2.ˊ.get("android:changeImageTransform:bounds");
        if (rect == null || rect2 == null) {
            return null;
        }
        Matrix matrix = (Matrix) nxVar.ˊ.get("android:changeImageTransform:matrix");
        Matrix matrix2 = (Matrix) nxVar2.ˊ.get("android:changeImageTransform:matrix");
        Object obj = (!(matrix == null && matrix2 == null) && (matrix == null || !matrix.equals(matrix2))) ? null : 1;
        if (rect.equals(rect2) && obj != null) {
            return null;
        }
        Animator ˎ;
        ImageView imageView = (ImageView) nxVar2.ॱ;
        Drawable drawable = imageView.getDrawable();
        int intrinsicWidth = drawable.getIntrinsicWidth();
        int intrinsicHeight = drawable.getIntrinsicHeight();
        nh.ˏ(imageView);
        if (intrinsicWidth == 0 || intrinsicHeight == 0) {
            ˎ = ˎ(imageView);
        } else {
            if (matrix == null) {
                matrix = ng.ˎ;
            }
            if (matrix2 == null) {
                matrix2 = ng.ˎ;
            }
            ʻ.set(imageView, matrix);
            ˎ = ˊ(imageView, matrix, matrix2);
        }
        nh.ˏ(imageView, ˎ);
        return ˎ;
    }

    private ObjectAnimator ˎ(ImageView imageView) {
        return ObjectAnimator.ofObject(imageView, ʻ, ᐝ, new Matrix[]{null, null});
    }

    private ObjectAnimator ˊ(ImageView imageView, Matrix matrix, Matrix matrix2) {
        return ObjectAnimator.ofObject(imageView, ʻ, new nu$b(), new Matrix[]{matrix, matrix2});
    }

    private static Matrix ˏ(ImageView imageView) {
        switch (AnonymousClass3.ˊ[imageView.getScaleType().ordinal()]) {
            case 1:
                return ॱ(imageView);
            case 2:
                return ˋ(imageView);
            default:
                return new Matrix(imageView.getImageMatrix());
        }
    }

    private static Matrix ॱ(ImageView imageView) {
        Drawable drawable = imageView.getDrawable();
        Matrix matrix = new Matrix();
        matrix.postScale(((float) imageView.getWidth()) / ((float) drawable.getIntrinsicWidth()), ((float) imageView.getHeight()) / ((float) drawable.getIntrinsicHeight()));
        return matrix;
    }

    private static Matrix ˋ(ImageView imageView) {
        Drawable drawable = imageView.getDrawable();
        int intrinsicWidth = drawable.getIntrinsicWidth();
        int width = imageView.getWidth();
        float f = ((float) width) / ((float) intrinsicWidth);
        int intrinsicHeight = drawable.getIntrinsicHeight();
        int height = imageView.getHeight();
        f = Math.max(f, ((float) height) / ((float) intrinsicHeight));
        float f2 = ((float) intrinsicHeight) * f;
        intrinsicWidth = Math.round((((float) width) - (((float) intrinsicWidth) * f)) / 2.0f);
        intrinsicHeight = Math.round((((float) height) - f2) / 2.0f);
        Matrix matrix = new Matrix();
        matrix.postScale(f, f);
        matrix.postTranslate((float) intrinsicWidth, (float) intrinsicHeight);
        return matrix;
    }
}
